import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MyButtonEvent {
	public static void main(String [] args) {
		JFrame frame = new JFrame("Button event test");
		frame.setSize(500,500);
		JPanel panel = new JPanel();
		frame.add(panel);
		placeComponent(panel);
		frame.setVisible(true);
	}
	public static void placeComponent(JPanel panel) {
		JButton button = new JButton("click me");
		button.setPreferredSize(new Dimension(300,30));
		panel.add(button);
		
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				button.setLabel(getnowTime()+"clicked button");
			}
		});
		
		JLabel label = new JLabel("time");
		label.setBounds(80,20,50,30);
		panel.add(label);
	}
	public static String getnowTime() {
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		return sdf.format(new java.util.Date(System.currentTimeMillis()));
	}
	
}
